package com.it.emall.mapper;

import org.apache.ibatis.annotations.*;

@Mapper
public interface LikesMapper {
    /**
     * 检查用户是否已经点赞某个食谱
     */
    @Select("SELECT COUNT(*) FROM recommendations WHERE user_id = #{userId} AND recipe_id = #{recipeId}")
    boolean isUserLikedRecipe(@Param("userId") int userId, @Param("recipeId") int recipeId);

    /**
     * 添加点赞记录
     */
    @Insert("INSERT INTO recommendations (user_id, recipe_id, recommended_at) VALUES (#{userId}, #{recipeId}, NOW())")
    int addLike(@Param("userId") int userId, @Param("recipeId") int recipeId);

    /**
     * 取消点赞记录
     */
    @Delete("DELETE FROM recommendations WHERE user_id = #{userId} AND recipe_id = #{recipeId}")
    int removeLike(@Param("userId") int userId, @Param("recipeId") int recipeId);
}
